package com.broad.data.storage.mybatis.dao.mapper;

import com.broad.data.storage.common.model.UserInfo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserInfoMapper {

    @Insert("insert into user_info (id,name,password,detail,create_time) values " +
            "(#{user.id},#{user.name},#{user.password},#{user.detail},#{user.createTime})")
    void addUser(@Param("user") UserInfo userInfo);

    @Update("update user_info set deleted=0 where id=#{uid}")
    void deleteUser(@Param("uid") String uid);

    @Update("update user_info set password=#{password} , detail=#{detail} where id=#{uid} and deleted=0")
    void updateUser(@Param("uid") String uid, @Param("password") String password, @Param("detail") String detail);

    @Select("select * from user_info where id=#{uid} and deleted=0")
    @ResultMap(value = "userInfoMap")
    UserInfo getUserInfoSelective(@Param("uid") String userId);

    @Select("select * from user_info where name = #{name} and deleted=0")
    @ResultMap(value = "userInfoMap")
    UserInfo getUserInfoByName(@Param("name") String username);

    @Select("select * from user_info where name=#{name} and password=#{password} and deleted=0")
    @ResultMap(value = "userInfoMap")
    UserInfo selectByUserNameAndPassword(@Param("name") String username, @Param("password") String password);
}
